/**
 * 
 */
package hu.gbalage.dml;

import java.io.OutputStream;

import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfWriter;

import document.Chunk;
import document.Document;

/**
 * @author balage
 *
 */
public class Generator {

	public void generate(Document doc, OutputStream out) throws DocumentException{
		com.lowagie.text.Document document = new com.lowagie.text.Document(PageSize.A4);
		
		PdfWriter.getInstance(document, out);
		
		document.open();
		
		for(document.Element e : doc.getElements()){
			Element de = generate(e);
			if (de != null)
				document.add(de);
		}
		
		document.close();
	}
	
	public Element generate(document.Element element){
		
		if (element instanceof Chunk){
			return new com.lowagie.text.Chunk(((Chunk) element).getText());
		}
		
		return null;
		
	}
}
